package com.jiepos.mpos.pay.quickpay.service.yeepay;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jiepos.mpos.common.constant.DBConstant.Table;
import com.jiepos.mpos.common.constant.SystemConstant;
import com.jiepos.mpos.common.dao.AppLogTransJnlsDao;
import com.jiepos.mpos.core.util.DateUtil;
import com.jiepos.mpos.core.util.GlobalUtils;
import com.jiepos.mpos.core.util.MathUtils;
import com.jiepos.mpos.core.util.StringUtils;
import com.jiepos.mpos.pay.AppLogTransJnlsPayService;
import com.jiepos.mpos.pay.CommonService;
import com.jiepos.mpos.pay.NoticeService;
import com.jiepos.mpos.pay.quickpay.service.AtrPayService;
import com.jiepos.mpos.pay.quickpay.service.IQuickPayService;




/**
* 标题: 快捷支付通道(易宝) 
* 模块: 支付平台 
* 版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
* @author 杨剑武
* @version 1.0
* @since 2017年12月27日
* @history（历次修订内容、修订人、修订时间等）
*/
@Service("YEEPAY_TERM")
@SuppressWarnings("rawtypes")
public class YeePayService extends AtrPayService implements IQuickPayService {
	private static final Logger _log = LoggerFactory.getLogger(YeePayService.class);
	
	@Autowired
	protected AppLogTransJnlsPayService appLogTransJnlsPayService;
	@Autowired
	protected NoticeService noticeService;
	@Autowired
	private AppLogTransJnlsDao appLogTransJnlsDao;
	/**
	 * 接口: <模块>
	 * 描 述: <描述>
	 * @param channelMchntCd
	 * @param orderNo
	 * @param orderAmt
	 * @param mobile
	 * @param certNo
	 * @param userName
	 * @param cardNo
	 * @param remark
	 * @param dataMap
	 * @return
	 * @since 2017年12月27日
	*/		
	@Override
	public Map payOrder(String channelMchntCd, String orderNo, String orderAmt, String mobile, String certNo,
			String userName, String cardNo, String remark, Map dataMap) {
		PostMethod postMethod = new PostMethod(GlobalUtils.getPayConfProperty("yeepay.serverurl"));
		HttpClient client = new HttpClient();
		try {
			String sign = hmacSign(dataMap);
			Part[] parts = new ReceviePartsBuiler()
					.setMainCustomerNumber(GlobalUtils.getPayConfProperty("yeepay.main.customer.number"))
					.setAmount(String.valueOf(dataMap.get("trans_at")))
					.setCallBackUrl(dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.call.back.url"))
					.setCustomerNumber(String.valueOf(dataMap.get("trf_mchnt_cd")))
					.setHamc(sign)
					.setMcc(GlobalUtils.getPayConfProperty("yeepay.mcc"))
					.setMobileNumber(String.valueOf(dataMap.get("phone")))
					.setRequestId(String.valueOf(dataMap.get("loc_trace_no")))
					.setSource(GlobalUtils.getPayConfProperty("yeepay.source"))
					.setWebCallBackUrl(dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.web.call.back.url"))
					.setPayerBankAccountNo(String.valueOf(dataMap.get("act_out_no")))
					.setAutoWithdraw(GlobalUtils.getPayConfProperty("yeepay.auto.with.draw"))
					.setWithdrawCardNo("")//到账卡号未传
					.generateParams();
			postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
			_log.info("易宝支付请求数据为:[mainCustomerNumber={},amount={},callBackUrl={},customerNumber={},hamc={},mcc={},mobileNumber={},requestId={},source={},webCallBackUrl={},payerBankAccountNo={},autoWithdraw={}]"
					,GlobalUtils.getPayConfProperty("yeepay.main.customer.number"),dataMap.get("trans_at"),dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.call.back.url"),
					dataMap.get("trf_mchnt_cd"),sign,GlobalUtils.getPayConfProperty("yeepay.mcc"),dataMap.get("phone"),dataMap.get("loc_trace_no"),
					GlobalUtils.getPayConfProperty("yeepay.source"),dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.web.call.back.url"),
					dataMap.get("act_out_no"),GlobalUtils.getPayConfProperty("yeepay.auto.with.draw"));
			int status = client.executeMethod(postMethod);
			if (status == HttpStatus.SC_OK) {
				String result = postMethod.getResponseBodyAsString();
				_log.info("易宝支付响应数据为:[{}]",result);
				if (!StringUtils.isEmpty(result)) {
					Map<String, String> reqMap = new HashMap<String, String>();
					JSONObject jsonResult = JSONObject.parseObject(result);
					reqMap.put("rspcode", jsonResult.getString("code"));
					reqMap.put("rspmsg", jsonResult.getString("message"));
					String url = jsonResult.getString("url");
					if (!StringUtils.isEmpty(url)) {
						url = AESUtil.decrypt(url, GlobalUtils.getPayConfProperty("yeepay.hmacKey"));
						reqMap.put("loc_trace_no", String.valueOf(dataMap.get("loc_trace_no")));
						//reqMap.put("url", url);
						reqMap.put("sourceData", htmlData(url));
						return getStandardData(reqMap);
					}
				}
			} else if (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY) {
				// 从头中取出转向的地址
				Header locationHeader = postMethod.getResponseHeader("location");
				String location = null;
				if (locationHeader != null) {
					location = locationHeader.getValue();
					_log.warn("The page was redirected to:[{}]" + location);
				} else {
					_log.error("Location field value is null.");
				}
			} else {
				_log.error("易宝支付https响应结果:[{}]",status);
			}
			return null;
		} catch (Exception e) {
			_log.error("易宝支付发生异常", e);
			return null;
		} finally {
			// 释放连接
			postMethod.releaseConnection();
		}
	}

	/**
	 * 接口: <模块>
	 * 描 述: <描述>
	 * @param paramMap
	 * @return
	 * @since 2017年12月27日
	*/
		
	@Override
	public boolean noticeOrder(Map<String, String> paramMap) {
		// TODO Auto-generated method stub
		Map<String, String> standardMap=new HashMap<String, String>();
		boolean flag = false;
		if("1".equals(paramMap.get("noticeFlag"))){
			standardMap = transNoticeStandard(paramMap);			
			flag=appLogTransJnlsDao.updateTransInfo(standardMap);
			if(SystemConstant.SUCCESS.equals(standardMap.get("withdrawFlag"))){
				Map<String, String> infoMap = appLogTransJnlsPayService.getTranInfo(standardMap.get("loc_trace_no"));
				//初始化渠道结算流水
				flag=appLogTransJnlsDao.initLogChannelStl(infoMap, standardMap,paramMap);
				//System.out.println("请求结算接口");
				Map withdrawMap=withdrawRequest(standardMap,paramMap);
				Map<String, String> withdrawRspStandard=withdrawRspStandard(withdrawMap);
				//同步返回失败更新清算状态和描述
				if(SystemConstant.AUDIT_STL_2.equals(withdrawRspStandard.get("stlst"))){					
					appLogTransJnlsDao.updateStlMsgFail(withdrawRspStandard);
					appLogTransJnlsDao.updateLogChannelStl(withdrawRspStandard);
				}
			}			
					
		}else if("2".equals(paramMap.get("noticeFlag"))){
			standardMap = withdrawNoticeStandard(paramMap);
			try {			
				flag=appLogTransJnlsDao.updateYeepaySerialno(standardMap);
			} catch (Exception e) {
				flag = false;
				_log.error("易宝结算异步通知更新发生异常", e);
			}
			
		}
		return flag;
		
	}
	/**
	 * 结算同步返回转换
	 * @param payResMap
	 * @return
	 */
	private Map<String, String> withdrawRspStandard(Map<String, Object> payResMap) {		
		Map<String, String> standardDataMap = new HashMap<String, String>();
		String rspcode=CommonService.encapResultCode(String.valueOf(payResMap.get("code")));
		Map<String, String> infoMap = appLogTransJnlsPayService.selectLogChannelStl(String.valueOf(payResMap.get("externalNo")));
		standardDataMap.put("loc_trace_no", String.valueOf(infoMap.get("loc_trace_no")));// 本地流水号
		standardDataMap.put("req_sn_no", String.valueOf(payResMap.get("externalNo")));// 结算请求号
		standardDataMap.put("stlst", SystemConstant.RSPCODE_SUCCESS.equals(rspcode)?"":SystemConstant.AUDIT_STL_2);// 清算状态（出款状态）		
		standardDataMap.put("stlcode", String.valueOf(payResMap.get("code")));// 结算响应码
		standardDataMap.put("stlmsg", String.valueOf(payResMap.get("message")));// 结算响应消息
		_log.info("易宝结算接口同步返回转换报文map=[{}]", standardDataMap);
		return standardDataMap;
	}
	
	/**
	 * 支付回调标准化报文
	 * @param payResMap
	 * @return
	 */
	private Map<String, String> transNoticeStandard(Map<String, String> payResMap) {		
		Map<String, String> standardDataMap = new HashMap<String, String>();
		standardDataMap.put("trf_mchnt_cd", "");// 商户编号（渠道）
		standardDataMap.put("trf_term_id", "");// 终端编号（渠道）		
		String complete_dt=StringUtils.isBlank(String.valueOf(payResMap.get("payTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(payResMap.get("payTime"))),"yyyyMMdd");
		String complete_ts=StringUtils.isBlank(String.valueOf(payResMap.get("payTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(payResMap.get("payTime"))),"HHmmss");
		standardDataMap.put("complete_dt", complete_dt);// 订单完成日期（渠道）
		standardDataMap.put("complete_ts", complete_ts);// 订单完成时间（渠道）
		standardDataMap.put("custom_no", "");// 商户编号（支付系统）
		standardDataMap.put("term_id", "");// 终端编号（支付系统）
		standardDataMap.put("trf_trace_no", payResMap.get("externalld"));// 渠道方流水号（渠道）
		standardDataMap.put("loc_trace_no", payResMap.get("requestId"));// 本地流水号（支付系统）
		String rspcode = CommonService.encapRespCode(payResMap.get("status"), null);
		String rspmsg = SystemConstant.RSPCODE_SUCCESS.equals(rspcode) ? SystemConstant.RSPCODE_SUCCESS_PAY
				: String.valueOf(noticeService.getRspCodeListMap().get(rspcode));
		standardDataMap.put("trs_stat",rspcode);// 交易状态		
		standardDataMap.put("stlst", "0");// 清算状态（出款状态）
		standardDataMap.put("stl_dt", "");// 清算日期			
		standardDataMap.put("midfee", "");// 商户手续费	
		standardDataMap.put("rcvfee", StringUtils.isBlank(String.valueOf(payResMap.get("fee")))?"0":String.valueOf(MathUtils.mul(Double.parseDouble(String.valueOf(payResMap.get("fee"))), Double.parseDouble("100"))));// 接收方手续费
		standardDataMap.put("costfee", "");// 成本手续费	
		standardDataMap.put("stl_amt", "");// 结算金额
		standardDataMap.put("trans_at", StringUtils.isBlank(String.valueOf(payResMap.get("amount")))?"0":String.valueOf(MathUtils.mul(Double.parseDouble(String.valueOf(payResMap.get("amount"))), Double.parseDouble("100"))));// 交易金额		
		
		standardDataMap.put("rspcode", rspcode);// 返回码
		standardDataMap.put("rspmsg", rspmsg);// 返回信息描述
		standardDataMap.put("pay_dt", "");// 出款日期
		standardDataMap.put("pay_ts", "");// 出款时间
		_log.info("易宝收款回调标准化异步通知报文map=[{}]", standardDataMap);
		return standardDataMap;
	}
	
	/**
	 * 结算回调标准化报文
	 * @param payResMap
	 * @return
	 */
	private Map<String, String> withdrawNoticeStandard(Map<String, String> payResMap) {		
		Map<String, String> standardDataMap = new HashMap<String, String>();
		Map<String, String> infoMap = appLogTransJnlsPayService.selectLogChannelStl(payResMap.get("externalNo"));
		
		standardDataMap.put("trf_mchnt_cd", "");// 商户编号（渠道）
		standardDataMap.put("trf_term_id", "");// 终端编号（渠道）		
		
		standardDataMap.put("complete_dt", "");// 订单完成日期（渠道）
		standardDataMap.put("complete_ts", "");// 订单完成时间（渠道）
		standardDataMap.put("custom_no", "");// 商户编号（支付系统）
		standardDataMap.put("term_id", "");// 终端编号（支付系统）
		standardDataMap.put("trf_trace_no", "");// 渠道方流水号（渠道）
		standardDataMap.put("loc_trace_no", infoMap.get("loc_trace_no"));// 本地流水号（支付系统）
		standardDataMap.put("req_sn_no", payResMap.get("externalNo"));// 结算请求号
		standardDataMap.put("trf_stl_trace_no", "");// 渠道清算流水号（支付系统）
		standardDataMap.put("yeepay_serialno", payResMap.get("serialNo"));// 易宝收款宝流水号
		standardDataMap.put("trs_stat","");// 交易状态	
		String stlst=CommonService.encapSettleRespCode(payResMap.get("transferStatus"));
		standardDataMap.put("stlst", stlst);// 清算状态（出款状态）
		String stl_dt=StringUtils.isBlank(String.valueOf(payResMap.get("handleTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(payResMap.get("handleTime"))),"yyyyMMdd");
		String stl_ts=StringUtils.isBlank(String.valueOf(payResMap.get("handleTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(payResMap.get("handleTime"))),"HHmmss");
		standardDataMap.put("stl_dt", stl_dt);// 清算日期	
		double stlfee=MathUtils.mul(MathUtils.add(Double.parseDouble(StringUtils.isBlank(String.valueOf(payResMap.get("basicFee")))?"0":String.valueOf(payResMap.get("basicFee"))), Double.parseDouble(StringUtils.isBlank(String.valueOf(payResMap.get("exTargetFee")))?"0":String.valueOf(payResMap.get("exTargetFee")))), Double.parseDouble("100"));
		double rcvfee=MathUtils.add(MathUtils.mul(Double.parseDouble(String.valueOf(infoMap.get("rcvfee"))), Double.parseDouble("100")), stlfee);
		standardDataMap.put("midfee", "");// 商户手续费	
		standardDataMap.put("rcvfee", String.valueOf(rcvfee));// 接收方手续费
		standardDataMap.put("costfee", "");// 成本手续费			
		standardDataMap.put("stlfee", String.valueOf(stlfee));// 结算手续费	
		standardDataMap.put("stl_amt", StringUtils.isBlank(String.valueOf(payResMap.get("actualAmount")))?"0":String.valueOf(MathUtils.mul(Double.parseDouble(String.valueOf(payResMap.get("actualAmount"))), Double.parseDouble("100"))));// 结算金额
		standardDataMap.put("trans_at", "");// 交易金额		
		standardDataMap.put("rspcode", SystemConstant.AUDIT_STL_1.equals(stlst)?SystemConstant.RSPCODE_SUCCESS:SystemConstant.RSPCODE_XX);// 返回码
		standardDataMap.put("rspmsg", "");// 返回信息描述
		standardDataMap.put("pay_dt", stl_dt);// 出款日期
		standardDataMap.put("pay_ts", stl_ts);// 出款时间
		String stlcode=CommonService.encapStlResultCode(payResMap.get("transferStatus"));
		String stlmsg = String.valueOf(noticeService.getRspCodeListMap().get(stlcode));
		standardDataMap.put("stlcode", stlcode);// 结算响应码
		standardDataMap.put("stlmsg", stlmsg);// 结算响应消息
		_log.info("易宝结算回调标准化异步通知报文map=[{}]", standardDataMap);
		return standardDataMap;
	}


	/**
	 * 接口: <模块>
	 * 描 述: <描述>
	 * @param queryMap
	 * @return
	 * @since 2017年12月27日
	*/
		
	@Override
	public Map<String, String> queryChannelOrder(Map<String, String> queryMap) {
		// TODO Auto-generated method stub
		_log.info("易宝主动查询请求的map[{}]", queryMap);
		try {
			String prefixUrl=GlobalUtils.getPayConfProperty("yeepay.withdraw.callback.prefixUrl");
			Map<String, String> tradeReceiveMap = tradeReceiveQuery(queryMap);
			
			Map<String, String> standardMap=tradeStandard(tradeReceiveMap,queryMap.get("loc_trace_no"));
			if(SystemConstant.RSPCODE_SUCCESS.equals(standardMap.get("rspcode"))){								
				appLogTransJnlsDao.updateTransInfo(standardMap);
				if(SystemConstant.SUCCESS.equals(standardMap.get("withdrawFlag"))){
					Map<String, String> infoMap = appLogTransJnlsPayService.getTranInfo(queryMap.get("loc_trace_no"));
					//初始化渠道结算流水
					appLogTransJnlsDao.initLogChannelStl(infoMap, standardMap,queryMap);
					queryMap.put("prefixUrl", prefixUrl);
					//System.out.println("请求结算接口");					
					Map withdrawMap=withdrawRequest(standardMap,queryMap);
					Map<String, String> withdrawRspStandard=withdrawRspStandard(withdrawMap);
					//同步返回失败更新清算状态和描述
					if(SystemConstant.AUDIT_STL_2.equals(withdrawRspStandard.get("stlst"))){					
						appLogTransJnlsDao.updateStlMsgFail(withdrawRspStandard);
						appLogTransJnlsDao.updateLogChannelStl(withdrawRspStandard);
						standardMap.put("stlst", SystemConstant.AUDIT_STL_2);
					}
				}
				
			}			
			return standardMap;
		}catch (Exception e) {
			_log.error("易宝主动查询请求发生异常", e);
			return new HashMap<String, String>();
		}
	}
	
	/**
	 * 查询渠道清算结果
	 */
	@Override
	public Map<String, String> queryChannelStlResult(Map<String, String> queryMap) {
		// TODO Auto-generated method stub
		_log.info("易宝主动查询清算结果请求的map[{}]", queryMap);
		try{
			Map<String, String> transferMap = transferQuery(queryMap);
			return withdrawStandard(transferMap,queryMap);
			
		}catch (Exception e) {
			_log.error("易宝主动查询请求发生异常", e);
			return new HashMap<String, String>();
		}		
	}
	
	/**
	 * 支付查询标准化报文
	 * @param tradeReceiveMap
	 * @param loc_trace_no
	 * @return
	 */
	private Map<String, String> tradeStandard(Map<String, String> tradeReceiveMap,String loc_trace_no){
		Map<String, String> respMap = new HashMap<String, String>();
		Map<String, String> infoMap = appLogTransJnlsPayService.getTranInfo(loc_trace_no);
		respMap.put("trf_mchnt_cd", infoMap.get("trf_mchnt_cd"));// 商户编号（渠道）
		respMap.put("trf_term_id", infoMap.get("trf_term_id"));// 终端编号（渠道）
		respMap.put("custom_no", infoMap.get("custom_no"));// 客户编号（支付系统）
		respMap.put("loc_trace_no", loc_trace_no);// 本地流水号（支付系统)
		respMap.put("stlst", infoMap.get("stlst"));// 清算状态(待定)
		respMap.put("trans_at", String.valueOf(MathUtils.mul(Double.valueOf(infoMap.get("trans_at")), 100)));// 交易金额(数据库查询)
		respMap.put("midfee", String.valueOf(MathUtils.mul(Double.valueOf(infoMap.get("midfee")), 100)));// 商户手续费
		String rspcode = infoMap.get("rspcode");// 返回码
		String rspmsg = infoMap.get("rspmsg");// 交易返回信息
		if (tradeReceiveMap!=null&&!tradeReceiveMap.isEmpty()) {
			rspcode=CommonService.encapResultCode(String.valueOf(tradeReceiveMap.get("code")));			
			if(SystemConstant.RSPCODE_SUCCESS.equals(rspcode)){												
				String complete_dt=StringUtils.isBlank(String.valueOf(tradeReceiveMap.get("payTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(tradeReceiveMap.get("payTime"))),"yyyyMMdd");
				String complete_ts=StringUtils.isBlank(String.valueOf(tradeReceiveMap.get("payTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(tradeReceiveMap.get("payTime"))),"HHmmss");
				respMap.put("complete_dt", complete_dt);// 订单完成日期（渠道）
				respMap.put("complete_ts", complete_ts);// 订单完成时间（渠道）
				respMap.put("term_id", "");// 终端编号（支付系统）
				respMap.put("trf_trace_no", String.valueOf(tradeReceiveMap.get("externalId")));// 渠道方流水号（渠道）
				respMap.put("trs_stat", CommonService.encapRespCode(String.valueOf(tradeReceiveMap.get("status")), null));// 交易状态
				respMap.put("stl_dt", "");// 清算日期				
				respMap.put("stl_amt", "");// 结算金额
				respMap.put("stlst", "0");// 清算状态				
				respMap.put("midfee", "");// 商户手续费
				respMap.put("rcvfee", StringUtils.isBlank(String.valueOf(tradeReceiveMap.get("fee")))?"0":String.valueOf(MathUtils.mul(Double.valueOf(tradeReceiveMap.get("fee")), 100)));// 接收方手续费
				respMap.put("costfee", "");// 成本手续费
				respMap.put("pay_dt", "");// 出款日期
				respMap.put("pay_ts", "");// 出款时间
				rspcode = CommonService.encapRespCode(String.valueOf(tradeReceiveMap.get("status")), null);
				rspmsg = SystemConstant.RSPCODE_SUCCESS.equals(rspcode) ? SystemConstant.RSPCODE_SUCCESS_PAY
						: String.valueOf(noticeService.getRspCodeListMap().get(rspcode));	
			}else{
				respMap.put("errorCode", String.valueOf(tradeReceiveMap.get("code")));// 渠道返回码
				respMap.put("msg", String.valueOf(tradeReceiveMap.get("message")));// 渠道返回信息
				rspcode=CommonService.encapRespCode(rspcode,null);
				rspmsg = StringUtils.isBlank( String.valueOf(tradeReceiveMap.get("message"))) ? 
						String.valueOf(noticeService.getRspCodeListMap().get(rspcode)): String.valueOf(tradeReceiveMap.get("message"));
			}
		}	
		
		respMap.put("rspcode", rspcode);// 返回码
		respMap.put("rspmsg", rspmsg);// 交易返回信息
		_log.info("易宝支付主动查询标准报文map=[{}]", respMap);
		return respMap;
	}
	
	/**
	 * 结算查询标准化报文
	 * @param transferMap
	 * @param standardMap
	 */
	private Map<String, String> withdrawStandard(Map<String, String> transferMap,Map<String, String> queryMap){
		Map<String, String> respMap = new HashMap<String, String>();
		Map<String, String> infoMap = appLogTransJnlsPayService.selectLogChannelStl(transferMap.get("requestNo"));
		if (transferMap!=null&&!transferMap.isEmpty()) {					
			if(SystemConstant.RSPCODE_SUCCESS.equals(CommonService.encapResultCode(String.valueOf(transferMap.get("code"))))){																				
				respMap.put("trf_mchnt_cd", "");// 商户编号（渠道）
				respMap.put("trf_term_id", "");// 终端编号（渠道）		
				
				respMap.put("complete_dt", infoMap.get("complete_dt"));// 订单完成日期（渠道）
				respMap.put("complete_ts", "");// 订单完成时间（渠道）
				respMap.put("custom_no", "");// 商户编号（支付系统）
				respMap.put("term_id", "");// 终端编号（支付系统）
				respMap.put("trf_trace_no", "");// 渠道方流水号（渠道）
				respMap.put("loc_trace_no", queryMap.get("loc_trace_no"));// 本地流水号（支付系统）
				respMap.put("req_sn_no", transferMap.get("requestNo"));// 结算请求号
				respMap.put("trf_stl_trace_no", transferMap.get("batchNo"));// 渠道清算流水号（支付系统）
				respMap.put("trs_stat","");// 交易状态	
				String stlst=CommonService.encapSettleRespCode(transferMap.get("transferStatus"));
				respMap.put("stlst", stlst);// 清算状态（出款状态）
				String stl_dt=StringUtils.isBlank(String.valueOf(transferMap.get("handleTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(transferMap.get("handleTime"))),"yyyyMMdd");
				String stl_ts=StringUtils.isBlank(String.valueOf(transferMap.get("handleTime")))?"":DateUtil.toString(DateUtil.StrToDate(String.valueOf(transferMap.get("handleTime"))),"HHmmss");
				respMap.put("stl_dt", stl_dt);// 清算日期	
				double stlfee=MathUtils.mul(MathUtils.add(Double.parseDouble(StringUtils.isBlank(String.valueOf(transferMap.get("basicFee")))?"0":String.valueOf(transferMap.get("basicFee"))), Double.parseDouble(StringUtils.isBlank(String.valueOf(transferMap.get("extTargetFee")))?"0":String.valueOf(transferMap.get("extTargetFee")))), Double.parseDouble("100"));
				double rcvfee=MathUtils.add(MathUtils.mul(Double.parseDouble(String.valueOf(infoMap.get("rcvfee"))), Double.parseDouble("100")), stlfee);
				respMap.put("midfee", "");// 商户手续费
				respMap.put("rcvfee", String.valueOf(rcvfee));// 接收方手续费
				respMap.put("costfee", "");// 成本手续费	
				respMap.put("stlfee", String.valueOf(stlfee));// 结算手续费	
				respMap.put("stl_amt", StringUtils.isBlank(String.valueOf(transferMap.get("actualAmount")))?"0":String.valueOf(MathUtils.mul(Double.parseDouble(String.valueOf(transferMap.get("actualAmount"))), Double.parseDouble("100"))));// 结算金额
				respMap.put("trans_at", StringUtils.isBlank(String.valueOf(infoMap.get("trans_at")))?"0":String.valueOf(MathUtils.mul(Double.parseDouble(String.valueOf(infoMap.get("trans_at"))), Double.parseDouble("100"))));// 交易金额		
				respMap.put("rspcode", SystemConstant.AUDIT_STL_1.equals(stlst)?SystemConstant.RSPCODE_SUCCESS:"");// 返回码
				respMap.put("rspmsg", "");// 返回信息描述
				respMap.put("pay_dt", stl_dt);// 出款日期
				respMap.put("pay_ts", stl_ts);// 出款时间
				String stlcode=CommonService.encapStlResultCode(transferMap.get("transferStatus"));
				String stlmsg = String.valueOf(noticeService.getRspCodeListMap().get(stlcode));
				respMap.put("stlcode", stlcode);// 结算响应码
				respMap.put("stlmsg", stlmsg);// 结算响应消息
			}
		}	
		_log.info("易宝结算主动查询标准报文map=[{}]", respMap);
		return respMap;
		
	}
	
	/**
	 * 支付主动查询
	 * @param queryMap
	 * @return
	 */
	private Map<String, String> tradeReceiveQuery(Map<String, String> queryMap){
		//TODO
		Map<String, String> respMap=new HashMap<String, String>();
		String url=GlobalUtils.getPayConfProperty("yeepay.trans.query.url");
		String hmacKey=GlobalUtils.getPayConfProperty("yeepay.hmacKey");
		PostMethod postMethod = new PostMethod(url);
        HttpClient client = new HttpClient();
        postMethod.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; charset=UTF-8");
        StringBuffer sb=new StringBuffer();
		sb.append("select CODE_TP,CODE_VAL from ").append(Table.T_APP_CODE_LIST).append(" where REC_ST !='0' and ")
		.append(" CODE_TP='CLOSE_ORDER_TIME'");
		List<Map<String,String>> codeList =appLogTransJnlsDao.queryForList(sb.toString());
		String time="";
		if(codeList==null||codeList.size()==0){
			time=SystemConstant.CLOSE_ORDER_DEFAULT_TIME;//默认120分钟
		}else{
			time=String.valueOf(codeList.get(0).get("CODE_VAL"));
		}
		String createTimeBegin=DateUtil.toString(new Date(DateUtil.toDate(String.valueOf(queryMap.get("loc_dt"))+String.valueOf(queryMap.get("loc_ts")),"yyyyMMddHHmmss").getTime() - (long)5 * 60 * 1000));
		String createTimeEnd=DateUtil.toString(new Date(DateUtil.toDate(String.valueOf(queryMap.get("loc_dt"))+String.valueOf(queryMap.get("loc_ts")),"yyyyMMddHHmmss").getTime() + (long)Integer.parseInt(time) * 60 * 1000));
        NameValuePair[] param = {
                // 大商户编号
                new NameValuePair("mainCustomerNumber", GlobalUtils.getPayConfProperty("yeepay.main.customer.number")),
                // 小商户编号
                new NameValuePair("customerNumber", String.valueOf(queryMap.get("trf_mchnt_cd"))),
                
                // 交易订单号
                new NameValuePair("requestId", String.valueOf(queryMap.get("loc_trace_no"))),
                
                // 请求时间起始时间
                new NameValuePair("createTimeBegin", createTimeBegin),
                
                // 请求时间结束时间
                new NameValuePair("createTimeEnd", createTimeEnd),
                
                // 支付时间起始时间
                new NameValuePair("payTimeBegin", ""),
                // 支付时间结束时间
                new NameValuePair("payTimeEnd", ""),

                // 更新时间起始时间
                new NameValuePair("lastUpdateTimeBegin", ""),
                // 更新时间结束时间
                new NameValuePair("lastUpdateTimeEnd", ""),
                // 状态（不区分大小写） FAIL，SUCCESS，FROZEN，THAWED
                new NameValuePair("status", ""),
                // 业务类型（不区分大小写） COMMON ， ASSURE
                new NameValuePair("busiType", "COMMON"),
                // 分页-页码
                new NameValuePair("pageNo", "1"),
                // 签名串
                new NameValuePair("hmac", ""),

        };
        try {

            param[param.length - 1].setValue(hmacSign(param));
            _log.info("易宝收款主动查询请求数据为mainCustomerNumber:[{}],customerNumber:[{}],requestId:[{}],createTimeBegin:[{}],createTimeEnd:[{}]"
            		,GlobalUtils.getPayConfProperty("yeepay.main.customer.number"),String.valueOf(queryMap.get("trf_mchnt_cd"))
            		,String.valueOf(queryMap.get("loc_trace_no")),createTimeBegin,createTimeEnd);
            postMethod.setRequestBody(param);

            int status = client.executeMethod(postMethod);
            if (status == HttpStatus.SC_OK) {
                String result = postMethod.getResponseBodyAsString();
                              
                _log.info("易宝收款主动查询响应数据为:[{}]",result);
                if(!StringUtils.isBlank(result)){               	
                	Map<String, Object> resultMap=JSON.parseObject(result);
                	StringBuilder hmacStr = new StringBuilder();
                	hmacStr.append(StringUtils.objToString(resultMap.get("code")))
                	.append(StringUtils.objToString(resultMap.get("message")))
                	.append(StringUtils.objToString(resultMap.get("totalRecords")))
                	.append(StringUtils.objToString(resultMap.get("tradeReceives")));
                	
                	String localhmac = Digest.hmacSign(hmacStr.toString(), hmacKey);
                	//if(localhmac.equals(String.valueOf(resultMap.get("hmac")))){
                	List<Map> list=JSON.parseArray(String.valueOf(resultMap.get("tradeReceives")),Map.class);
                	for(Map map:list){
                		if(String.valueOf(queryMap.get("loc_trace_no")).equals(map.get("requestId"))){               			
                			respMap=map;
                			respMap.put("code", String.valueOf(resultMap.get("code")));
                        	respMap.put("message", String.valueOf(resultMap.get("message")));
                		}
                	}
                	
                	//}
                }

            } else if (status == HttpStatus.SC_MOVED_PERMANENTLY
                    || status == HttpStatus.SC_MOVED_TEMPORARILY) {
                // 从头中取出转向的地址
                Header locationHeader = postMethod
                        .getResponseHeader("location");
                String location = null;
                if (locationHeader != null) {
                    location = locationHeader.getValue();
                    _log.warn("The page was redirected to:" + location);
                } else {
                	_log.error("Location field value is null.");
                }
            } else {
            	_log.error("易宝收款主动查询失败:[{}]" + status);
            }
        } catch (Exception e) {
            _log.error("易宝收款主动查询发生异常",e);
        } finally {
            // 释放连接
            postMethod.releaseConnection();
        }
		return respMap;
	}
	
	/**
	 * 签名
	 * @param param
	 * @return
	 */
	private  String hmacSign(NameValuePair[] param) {
		//TODO
		String hmacKey=GlobalUtils.getPayConfProperty("yeepay.hmacKey");
        StringBuilder hmacStr = new StringBuilder();
        for (NameValuePair nameValuePair : param) {
            if (nameValuePair.getName().equals("hmac")) {
                continue;
            }
            hmacStr.append(nameValuePair.getValue() == null ? ""
                    : nameValuePair.getValue());

        }

        _log.info("参与签名字符串为;[{}]",hmacStr.toString());
        String hmac = Digest.hmacSign(hmacStr.toString(), hmacKey);
        _log.info("签名为;[{}]",hmac);       

        return hmac;
    }
	
	/**
	 * 结算查询
	 * @param queryMap
	 * @return
	 */
	private Map<String, String> transferQuery(Map<String, String> queryMap){
		//TODO
		Map<String, String> respMap=new HashMap<String, String>();
		String url=GlobalUtils.getPayConfProperty("yeepay.withdraw.query.url");
		String hmacKey=GlobalUtils.getPayConfProperty("yeepay.hmacKey");
		PostMethod postMethod = new PostMethod(url);

        HttpClient client = new HttpClient();
        postMethod.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; charset=UTF-8");
        
        StringBuffer sb=new StringBuffer();
		sb.append("select CODE_TP,CODE_VAL from ").append(Table.T_APP_CODE_LIST).append(" where REC_ST !='0' and ")
		.append(" CODE_TP='CLOSE_ORDER_TIME'");
		List<Map<String,String>> codeList =appLogTransJnlsDao.queryForList(sb.toString());
		String time="";
		if(codeList==null||codeList.size()==0){
			time=SystemConstant.CLOSE_ORDER_DEFAULT_TIME;//默认120分钟
		}else{
			time=String.valueOf(codeList.get(0).get("CODE_VAL"));
		}
		String requestDateSectionBegin=DateUtil.toString(new Date(DateUtil.toDate(String.valueOf(queryMap.get("loc_dt"))+String.valueOf(queryMap.get("loc_ts")),"yyyyMMddHHmmss").getTime() - (long)5 * 60 * 1000));
		String requestDateSectionEnd=DateUtil.toString(new Date(DateUtil.toDate(String.valueOf(queryMap.get("loc_dt"))+String.valueOf(queryMap.get("loc_ts")),"yyyyMMddHHmmss").getTime() + (long)Integer.parseInt(time) * 60 * 1000));
        NameValuePair[] param = {
                // 小商户编号
                new NameValuePair("customerNumber", String.valueOf(queryMap.get("trf_mchnt_cd"))),                

                new NameValuePair("externalNo", String.valueOf(queryMap.get("req_sn_no"))),
                
                // 大商户编号
                new NameValuePair("mainCustomerNumber", GlobalUtils.getPayConfProperty("yeepay.main.customer.number")),
                // 分页-页码
                new NameValuePair("pageNo", "1"),

                // 请求时间起始时间
                new NameValuePair("requestDateSectionBegin", requestDateSectionBegin),
                
                // 请求时间结束时间
                new NameValuePair("requestDateSectionEnd", requestDateSectionEnd),
                
                new NameValuePair("serialNo",""),
                // 出款状态 /** * 已接收 */ RECEIVED, /** * 处理中 */ PROCESSING, /** * 打款成功
                // */ SUCCESSED, /** * 打款失败 */ FAILED, /** * 已退款 */ REFUNED;
                new NameValuePair("transferStatus", ""),
                // 出款方式 TRANSFERINDAY("1","日结通"),
                // TRANSFER("2","委托结算"),SETTLEMENT("3","商家结算");
                new NameValuePair("transferWay", "1"),

                // 签名串
                new NameValuePair("hmac", ""),

        };

        try {

            param[param.length - 1].setValue(hmacSign(param));

            _log.info("易宝结算主动查询请求数据为mainCustomerNumber:[{}],customerNumber:[{}],externalNo:[{}],requestDateSectionBegin:[{}],requestDateSectionEnd:[{}]"
            		,GlobalUtils.getPayConfProperty("yeepay.main.customer.number"),String.valueOf(queryMap.get("trf_mchnt_cd"))
            		,String.valueOf(queryMap.get("req_sn_no")),requestDateSectionBegin,requestDateSectionEnd);
            postMethod.setRequestBody(param);

            int status = client.executeMethod(postMethod);
            if (status == HttpStatus.SC_OK) {
                String result = postMethod.getResponseBodyAsString();
                
                _log.info("易宝结算主动查询响应数据为:" + result);   
                if(!StringUtils.isBlank(result)){                 	
                	Map<String, Object> resultMap=JSON.parseObject(result);
                	StringBuilder hmacStr = new StringBuilder();
                	hmacStr.append(StringUtils.objToString(resultMap.get("code")))
                	.append(StringUtils.objToString(resultMap.get("message")))
                	.append(StringUtils.objToString(resultMap.get("totalRecords")))
                	.append(StringUtils.objToString(resultMap.get("transferRequests")));
                	
                	String localhmac = Digest.hmacSign(hmacStr.toString(), hmacKey);
                	//if(localhmac.equals(String.valueOf(resultMap.get("hmac")))){
                	List<Map> list=JSON.parseArray(String.valueOf(resultMap.get("transferRequests")),Map.class);
                	for(Map map:list){
                		if(String.valueOf(queryMap.get("req_sn_no")).equals(map.get("requestNo"))){               			
                			respMap=map;
                			respMap.put("code", String.valueOf(resultMap.get("code")));
                        	respMap.put("message", String.valueOf(resultMap.get("message")));
                		}               		
                	}
                	
                	//}
                }

            } else if (status == HttpStatus.SC_MOVED_PERMANENTLY
                    || status == HttpStatus.SC_MOVED_TEMPORARILY) {
                // 从头中取出转向的地址
                Header locationHeader = postMethod
                        .getResponseHeader("location");
                String location = null;
                if (locationHeader != null) {
                    location = locationHeader.getValue();
                    _log.warn("The page was redirected to:" + location);
                } else {
                	_log.error("Location field value is null.");
                }
            } else {
            	_log.error("易宝结算主动查询失败:[{}]" + status);
            }
        } catch (Exception e) {          
            _log.error("易宝结算主动查询发生异常",e);
        } finally {
            // 释放连接
            postMethod.releaseConnection();
        }
		return respMap;
	}
	
	/**
	 * 结算接口
	 * @param queryMap
	 * @param paramsMap
	 * @return
	 */
	private Map withdrawRequest(Map<String, String> queryMap,Map<String, String> paramsMap){
		//TODO
		Map respMap=new HashMap();
		String url=GlobalUtils.getPayConfProperty("yeepay.withdraw.url");	
		String hmacKey=GlobalUtils.getPayConfProperty("yeepay.hmacKey");
		PostMethod postMethod = new PostMethod(url);

        HttpClient client = new HttpClient();
        postMethod.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded; charset=UTF-8");
        NameValuePair[] param = {
                // 出款金额
                new NameValuePair("amount", String.valueOf(MathUtils.div(MathUtils.sub(Double.parseDouble(String.valueOf(queryMap.get("trans_at"))), Double.parseDouble(String.valueOf(queryMap.get("rcvfee")))), Double.parseDouble("100"), 2))),
                // 小商户编号
                new NameValuePair("customerNumber", String.valueOf(queryMap.get("trf_mchnt_cd"))),
                // 出款订单号
                new NameValuePair("externalNo", String.valueOf(paramsMap.get("req_sn_no"))),
                // 大商户编号
                new NameValuePair("mainCustomerNumber", GlobalUtils.getPayConfProperty("yeepay.main.customer.number")),

                // 出款方式
                new NameValuePair("transferWay", "1"),

                new NameValuePair("callBackUrl",paramsMap.get("prefixUrl")+ GlobalUtils.getPayConfProperty("yeepay.withdraw.callback.url")),

                // 签名串
                new NameValuePair("hmac", ""),

        };

        try {

            param[param.length - 1].setValue(hmacSign(param));

            _log.info("易宝结算接口请求数据为mainCustomerNumber:[{}],customerNumber:[{}],externalNo:[{}],loc_trace_no:[{}],amount:[{}],callBackUrl:[{}]"
            		,GlobalUtils.getPayConfProperty("yeepay.main.customer.number"),String.valueOf(queryMap.get("trf_mchnt_cd"))
            		,String.valueOf(paramsMap.get("req_sn_no")),String.valueOf(queryMap.get("loc_trace_no")),String.valueOf(MathUtils.div(MathUtils.sub(Double.parseDouble(String.valueOf(queryMap.get("trans_at"))), Double.parseDouble(String.valueOf(queryMap.get("rcvfee")))), Double.parseDouble("100"), 2))
            		,paramsMap.get("prefixUrl")+ GlobalUtils.getPayConfProperty("yeepay.withdraw.callback.url"));
            postMethod.setRequestBody(param);

            int status = client.executeMethod(postMethod);
            if (status == HttpStatus.SC_OK) {
                String result = postMethod.getResponseBodyAsString();
                _log.info("易宝结算接口响应数据为;[{}]" + result); 
                if(!StringUtils.isBlank(result)){                 	
                	Map<String, Object> resultMap=JSON.parseObject(result);
                	StringBuilder hmacStr = new StringBuilder();
                	hmacStr.append(StringUtils.objToString(resultMap.get("amount")))
                	.append(StringUtils.objToString(resultMap.get("code")))
                	.append(StringUtils.objToString(resultMap.get("customerNumber")))
                	.append(StringUtils.objToString(resultMap.get("externalNo")))
                	.append(StringUtils.objToString(resultMap.get("mainCustomerNumber")))
                	.append(StringUtils.objToString(resultMap.get("message")))
                	.append(StringUtils.objToString(resultMap.get("serialNo")))
                	.append(StringUtils.objToString(resultMap.get("transferWay")));
                	
                	String localhmac = Digest.hmacSign(hmacStr.toString(), hmacKey);
                	if(localhmac.equals(String.valueOf(resultMap.get("hmac")))){
                		respMap=resultMap;
                	}
                }

            } else if (status == HttpStatus.SC_MOVED_PERMANENTLY
                    || status == HttpStatus.SC_MOVED_TEMPORARILY) {
                // 从头中取出转向的地址
                Header locationHeader = postMethod
                        .getResponseHeader("location");
                String location = null;
                if (locationHeader != null) {
                    location = locationHeader.getValue();
                    _log.warn("The page was redirected to:" + location);
                } else {
                	_log.error("Location field value is null.");
                }
            } else {
            	_log.error("易宝结算接口请求失败:[{}]" + status);
            }
        } catch (Exception e) {
            _log.error("易宝结算接口发生异常",e);
        } finally {
            // 释放连接
            postMethod.releaseConnection();
        }
		return respMap;
	}

	/**
	 * 接口: <模块>
	 * 描 述: <描述>
	 * @param reqMap
	 * @return
	 * @since 2017年12月27日
	*/
		
	@Override
	public Map<String, String> verifyCode(Map<String, String> reqMap) {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 接口: <模块>
	 * 描 述: <描述>
	 * @param reqMap
	 * @return
	 * @throws Exception
	 * @since 2017年12月27日
	*/
		
	@Override
	public Map<String, String> getStandardData(Map<String, String> reqMap) throws Exception {
		Map<String, String> respMap = new HashMap<String, String>();
		Assert.notNull(reqMap.get("loc_trace_no"));
		Map<String, String> infoMap = appLogTransJnlsPayService.getTranInfo(reqMap.get("loc_trace_no"));
		log.info("易宝支付响应报文为:[{}],[{}]交易对应的查询数据为:[{}]",reqMap,reqMap.get("loc_trace_no"),infoMap);
		Map<String, Object> traceTime = mainBusinessService.getSystemTime();
		respMap.put("loc_dt", String.valueOf(traceTime.get("loc_dt")));//交易日期
		respMap.put("loc_ts", String.valueOf(traceTime.get("loc_ts")));//交易日期
		respMap.put("trf_mchnt_cd", infoMap.get("trf_mchnt_cd"));// 商户编号（渠道）
		respMap.put("trf_term_id", infoMap.get("trf_term_id"));// 终端编号（渠道）
		respMap.put("complete_dt", reqMap.get("complete_dt"));// 订单完成日期（渠道）
		respMap.put("complete_ts", reqMap.get("complete_ts"));// 订单完成时间
		respMap.put("custom_no", infoMap.get("custom_no"));// 客户编号（支付系统）
		respMap.put("term_id", reqMap.get("term_id"));// 本地流水号（支付系统)
		respMap.put("trf_trace_no", reqMap.get("trf_trace_no"));// 渠道方流水号（渠道）
		respMap.put("loc_trace_no", reqMap.get("loc_trace_no"));
		respMap.put("trs_stat", reqMap.get("trs_stat"));// 交易状态
		respMap.put("stlst", infoMap.get("stlst"));// 清算状态
		respMap.put("midfee", infoMap.get("midfee"));// 商户手续费
		respMap.put("stl_amt", reqMap.get("stl_amt"));// 结算金额
		respMap.put("rspcode", reqMap.get("rspcode"));// 返回码
		respMap.put("rspmsg", reqMap.get("rspmsg"));// 交易返回信息
		respMap.put("action", reqMap.get("action_url"));// 银联跳转页面
		respMap.put("action_method", reqMap.get("action_method"));// 银联跳转页面
		respMap.put("data", reqMap.get("data"));// 支付数据
		respMap.put("url", reqMap.get("url"));// 未使用
		respMap.put("sourceData", reqMap.get("sourceData"));// 交易返回信息
		respMap.put("channel_type", SystemConstant.CHANNEL_TYPE_H5);
		log.info("易宝支付响应报文转标准化系统处理报文[{}]",respMap);
		return respMap;
	}
	/**
	 * 
	 * 接口: 支付接口组装签名数据
	 * @return
	 * @author 杨剑武
	 * @since 2017年12月28日
	 */
	 private String hmacSign(Map dataMap) {
	        StringBuilder hmacStr = new StringBuilder();
	        hmacStr.append(GlobalUtils.getPayConfProperty("yeepay.source") == null ? "" : GlobalUtils.getPayConfProperty("yeepay.source"))
            .append(GlobalUtils.getPayConfProperty("yeepay.main.customer.number") == null ? "" : GlobalUtils.getPayConfProperty("yeepay.main.customer.number"))
            .append(dataMap.get("trf_mchnt_cd") == null ? "" : String.valueOf(dataMap.get("trf_mchnt_cd")))
            .append(dataMap.get("trans_at") == null ? "" : String.valueOf(dataMap.get("trans_at")))
            .append(GlobalUtils.getPayConfProperty("yeepay.mcc") == null ? "" : GlobalUtils.getPayConfProperty("yeepay.mcc"))
            .append(dataMap.get("loc_trace_no") == null ? "" : String.valueOf(dataMap.get("loc_trace_no")))
            .append(dataMap.get("phone") == null ? "" : String.valueOf(dataMap.get("phone")))
            .append((dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.call.back.url")) == null ? "" : (dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.call.back.url")))
            .append((dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.web.call.back.url")) == null ? "" : (dataMap.get("payUrl") + GlobalUtils.getPayConfProperty("yeepay.web.call.back.url")))
            .append(dataMap.get("act_out_no") == null ? "" : String.valueOf(dataMap.get("act_out_no")));
	        _log.info("加密字符串明文为:[{}]",hmacStr.toString());
	        return Digest.hmacSign(hmacStr.toString(), GlobalUtils.getPayConfProperty("yeepay.hmacKey"));
	    }
	 
private	class ReceviePartsBuiler {

	    private List<Part> parts = new ArrayList<Part>(11);

	    public Part[] generateParams() {
	        return parts.toArray(new Part[parts.size()]);
	    }

	    public ReceviePartsBuiler setSource(String source) {
	        this.parts.add(new StringPart("source", source == null ? "" : source,
	                SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setMainCustomerNumber(String mainCustomerNumber) {
	        this.parts.add(new StringPart("mainCustomerNumber",
	                mainCustomerNumber == null ? "" : mainCustomerNumber, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setCustomerNumber(String customerNumber) {
	        this.parts.add(new StringPart("customerNumber",
	                customerNumber == null ? "" : customerNumber, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setRequestId(String requestId) {
	        this.parts.add(new StringPart("requestId", requestId == null ? ""
	                : requestId, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setAmount(String amout) {
	        this.parts.add(new StringPart("amount", amout == null ? "" : amout,
	                SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setMcc(String mcc) {
	        this.parts.add(new StringPart("mcc", mcc == null ? "" : mcc, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setMobileNumber(String mobileNumber) {
	        this.parts.add(new StringPart("mobileNumber", mobileNumber == null ? ""
	                : mobileNumber, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setCallBackUrl(String callBackUrl) {
	        this.parts.add(new StringPart("callBackUrl", callBackUrl == null ? ""
	                : callBackUrl, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setWebCallBackUrl(String webCallBackUrl) {
	        this.parts.add(new StringPart("webCallBackUrl",
	                webCallBackUrl == null ? "" : webCallBackUrl, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setPayerBankAccountNo(String payerBankAccountNo) {
	        this.parts.add(new StringPart("payerBankAccountNo",
	                payerBankAccountNo == null ? "" : payerBankAccountNo, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setHamc(String hmac) {
	        this.parts
	                .add(new StringPart("hmac", hmac == null ? "" : hmac, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	    public ReceviePartsBuiler setAutoWithdraw(String autoWithdraw) {
	        this.parts.add(new StringPart("autoWithdraw",
	                autoWithdraw == null ? "" : autoWithdraw, SystemConstant.UTF_ENCODING));
	        return this;
	    }
	    
	    public ReceviePartsBuiler setWithdrawCardNo(String withdrawCardNo) {
	        this.parts.add(new StringPart("withdrawCardNo",
	                withdrawCardNo == null ? "" : withdrawCardNo, SystemConstant.UTF_ENCODING));
	        return this;
	    }

	}

	/**
	 * 
	 * 接口:
	 * 
	 * @param url
	 * @return
	 * @since 2018年1月4日
	 */
	private String htmlData(String url) {
		StringBuilder builder = new StringBuilder("<html><head><meta charset='utf-8'/><title></title></head><script>");
		builder.append("window.location.href = '");
		builder.append(url);
		builder.append("'</script><body><body/></html>");
		return builder.toString();
	}

	@Override
	public Map<String, String> sendVerifyCode(Map<String, String> reqMap) {
		return null;
	}

	
}
